package com.miracle.mango.util;

import com.google.common.collect.Maps;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

/**
 * @description:
 * @author: wangxf
 * @date: Created in 2020/8/28 22:13
 */
public class JwtMain {
    public static void main(String[] args) {
//        String token = Jwts.builder().signWith(SignatureAlgorithm.HS256, "aaa")
//                .setSubject("username")
//                .setIssuedAt(new Date())
//                .setExpiration(new Date(System.currentTimeMillis() + 60 * 1000))
//                .compact();
//        System.out.println(token);

        printJwt();

    }

    /**
     * 可以生成jwt
     */
    private static void printJwt() {
        Map<String, Object> claims = Maps.newHashMap();
        claims.put("sub", "wangxf");
        claims.put("created", new Date());

        Date expirationDate = new Date(System.currentTimeMillis() + 1000L);
        String token1 = Jwts.builder().setClaims(claims)
                .setExpiration(expirationDate)
                .signWith(SignatureAlgorithm.HS512, "admin").compact();
        System.out.println("token：" + token1);

    }
}
